﻿using System.Collections.Generic;
using System.Linq;

namespace MediaOwl.WebSearch.Data
{
    public class VideoFilters
    {
        public const char Divider = ':';
        public const string All = "All";

        public enum FilterTypes
        {
            Duration, Aspect, Resolution
        }

        public const string DurationPrefix = "Duration";
        public const string AspectPrefix = "Aspect";
        public const string ResolutionPrefix = "Resolution";

        public static IList<string> Durations = new List<string>(4) { All, "Short", "Medium", "Long" };
        public static IList<string> Aspects = new List<string>(3) { All, "Standard", "Widescreen" };
        public static IList<string> Resolutions = new List<string>(4) { All, "Low", "Medium", "High" };

        internal static string GetFilter(string option, FilterTypes type)
        {
            if (string.IsNullOrEmpty(option) || option == All)
                return null;

            switch (type)
            {
                case FilterTypes.Duration:
                    return DurationPrefix + Divider + option;
                case FilterTypes.Aspect:
                    return AspectPrefix + Divider + option;
                case FilterTypes.Resolution:
                    return ResolutionPrefix + Divider + option;
            }
            return null;
        }

        internal static string[] GetFilter(string duration, string aspect, string resolution)
        {
            if (duration == All && aspect == All && resolution == All)
                return null;

            var sa = new[]
                         {
                             GetFilter(duration, FilterTypes.Duration),
                             GetFilter(aspect, FilterTypes.Aspect),
                             GetFilter(resolution, FilterTypes.Resolution)
                         };

            return sa.Where(x => !string.IsNullOrEmpty(x)).ToArray();
        }
    }
}